package com.mew.slots.core.game.ajxb.room;

import cn.hutool.core.util.RandomUtil;
import com.mew.common.util.GameUtil;
import com.mew.slots.core.common.game.BaseRoom;
import com.mew.slots.core.game.ajxb.roller.AjxbIli;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class AjxbRoom extends BaseRoom {

    public static int _SCATTER = 12;//_WILD不允许替换

    public static int[] jpWeights = {50,30,15,5};

    public AjxbRoom(){
        res = new AjxbPlayMsgs();
        row = 3;
        col = 5;
        _WILD = 11;
        spes = new ArrayList<Integer>(){{
            add(12);
        }};

        //9 0,10 1,j 2,q3, k 4, a 5,虫  6，鸟  7，牛  8，猫  9，人  10，W 11,  S  12

         rate = new int[][]{
                {0, 0,  5,   10, 50},
                {0, 0,  5,   10, 50},
                {0, 0,  5,   10, 50},
                {0, 0,  5,   10, 50},
                {0, 0,  5,   10, 50},
                {0, 0,  5,   10, 50},
                {0, 0,  10,   20, 100},
                {0, 0, 25,  50,  250},
                {0, 0, 40,  80,  400},
                {0, 0, 50,  100,  500},
                {0, 0,  100,  200,  1000},
                {0, 0,  0,   0,   0},
                {0, 0,  0,   0,   0},
        };

         alllines = new int[][]{
                 {5,6,7,8,9},
                 {0,1,2,3,4},
                 {10,11,12,13,14},
                 {0,6,12,8,4},
                 {10,6,2,8,14},
                 {5,1,7,13,9},
                 {5,11,7,3,9},
                 {0,1,7,13,14},
                 {10,11,7,3,4},
                 {0,6,2,8,4},
                 {10,6,12,8,14},
                 {5,1,2,3,9},
                 {5,11,12,13,9},
                 {0,6,7,8,4},
                 {10,6,7,8,14},
                 {5,6,2,8,9},
                 {5,6,12,8,9},
                 {5,1,7,3,9},
                 {5,11,7,13,9},
                 {0,1,2,8,14},
                 {10,11,12,8,4},
                 {0,6,12,13,14},
                 {10,6,2,3,4},
                 {5,6,7,3,14},
                 {5,6,7,13,4},
                 {0,6,7,8,14},
                 {10,6,7,8,4},
                 {10,11,7,3,9},
                 {0,1,7,13,9},
                 {10,6,12,13,14},
                 {0,6,2,3,4},
                 {0,6,12,8,9},
                 {10,6,2,8,9},
                 {5,1,7,3,4},
                 {5,11,7,13,14},
                 {0,6,7,8,9},
                 {10,6,7,8,9},
                 {5,1,2,3,4},
                 {5,11,12,13,14},
                 {5,6,7,8,4},
                 {5,6,7,8,14},
                 {0,1,7,3,4},
                 {10,11,7,13,14},
                 {0,1,2,8,4},
                 {10,11,12,8,14},
                 {5,6,2,3,4},
                 {5,6,12,13,14},
                 {0,1,7,8,4},
                 {10,11,7,8,14},
                 {10,6,2,8,4}
        };
    }

    @Override
    public void freeBouns(){
        int fsdb = fsdb(_SCATTER);
        if (fsdb>2){
            res.free = 1;
            res.freeNumber = 10;
        }

        if (controlType==3||(fsdb(_WILD)>0&& RandomUtil.randomInt(10000)<1)){
            res.bouns = 1;
            //开箱子
            Integer jpType = GameUtil.weights(jpWeights);
            res.jp =jpType+1;

            int[] jpRes = {0,0,1,1,2,2,3,3};
            List<Integer> list = Arrays.stream(jpRes).boxed().collect(Collectors.toList());
            list.add(jpType);
            Collections.shuffle(list);
            for (int i = 0; i < 4; i++) {
                if (i==jpType){
                    continue;
                }
                list.add(i);
            }

            ((AjxbPlayMsgs)res).bounsBox = list.stream().mapToInt(i->i).toArray();
            ((AjxbPlayMsgs)res).openBox = list.lastIndexOf(jpType);
        }
    }

/*    @Override
    public int[] control() {
        if (controlType==1){
            return bigwin();
        }

        if (controlType==2){
            int[] ints = new int[col * row];
            ints[2] = _SCATTER;
            ints[7] = _SCATTER;
            ints[12] = _SCATTER;
            return ints;
        }

        return super.control();
    }*/

    @Override
    public int[] control(){
        AjxbIli instance = AjxbIli.getInstance();
        switch (controlType) {
            case 1:
                instance.getSpeints("21-23");
            case 2:
                return instance.getSpeints("free");
            default:
                return instance.getSpeints("0-0");
        }
    }


    public static void main(String[] args) {
        Integer jpType = GameUtil.weights(jpWeights);
        ArrayList<Integer> jps = new ArrayList<>();
        int[] jpRes = {0,0,1,1,2,2,3,3};
        List<Integer> list = Arrays.stream(jpRes).boxed().collect(Collectors.toList());
        list.add(jpType);
        Collections.shuffle(list);
        for (int i = 0; i < 4; i++) {
            if (i==jpType){
                continue;
            }
            list.add(i);
        }
        int open = list.lastIndexOf(jpType);

        System.out.println(open);
        System.out.println(jpType);
        System.out.println(list);
    }
}
